package com.lam.mall.entity;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Size;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.lam.common.base.domain.BaseEntity;
import com.lam.common.components.dict.annotation.Dict;
import com.lam.common.components.dict.constant.DictTypeEnum;
import com.lam.common.utils.DateUtil;
import com.lam.common.validate.annotation.DictCheck;
import com.lam.common.validate.annotation.DictValid;
import com.lam.common.validate.group.Add;
import com.lam.mall.common.util.ProductUtil;

/**
 * 商品管理对象 mall_prod
 * 
 * @author admin
 * @date 2023-04-22
 */
@DictCheck
@TableName("mall_product")
public class Product implements BaseEntity{

    /** 主键 */
    @Null(groups = Add.class, message="id必须为空")
    @TableId(type = IdType.ASSIGN_ID)
    private String id;
    
    /** 商品名称 */
    @NotBlank(message = "商品名称不能为空")
    @Size(max = 300, message = "商品名称长度不能超过300个字符")
    private String prodName;

    /** 店铺id */
    private String shopId;

    /** 原价 */
    @NotNull(message = "原价不能为空")
    private BigDecimal oriPrice;

    /** 现价 */
    @NotNull(message = "现价不能为空")
    private BigDecimal price;

    /** 简要描述,卖点等 */
    @Size(max = 500, message = "简要描述,卖点等长度不能超过500个字符")
    private String brief;

    /** 详细描述 */
    @NotBlank(message = "详细描述不能为空")
    @Size(max = 65535, message = "详细描述长度不能超过65535个字符")
    private String content;

    /** 商品主图 */
//    @JsonSerialize(using = ImgJsonSerializer.class)
    @NotBlank(message = "商品主图不能为空")
    @Size(max = 255, message = "商品主图长度不能超过255个字符")
    private String pic;

    /** 商品图片，以,分割 */
    @NotBlank(message = "商品图片不能为空")
    @Size(max = 1000, message = "商品图片长度不能超过1000个字符")
    private String imgs;

    /** 状态,(1-正常, -1-删除, 0-下架) */
    @NotNull(message = "状态不能为空")
    @DictValid(message = "无效的状态,")
    @Dict(dictCode = "prod_status")
    private Integer status;

    /** 商品分类 */
    @NotNull(message = "商品分类不能为空")
    private String categoryId;
    
    /** sku规格属性 */
    private String skuProperties;

    /** 销量 */
    private Integer soldNum;

    /** 总库存 */
    private Integer totalStocks;

    /** 配送方式 */
    @NotBlank(message = "配送方式不能为空")
    @DictValid(message = "无效的配送方式")
    @Dict(dictCode = "delivery_mode")
    private String deliveryMode;

    /** 运费模板id */
    @DictValid(message = "无效的运费模板")
    @Dict(dictCode = "transDeeTemplate", dictType = DictTypeEnum.TABLE_DICT)
    private String deliveryTemplateId;

    /** 录入时间 */
    @JsonFormat(pattern = DateUtil.PATTERN_DEFAULT)
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    /** 创建人 */
    private String createBy;

    /** 修改时间 */
    @JsonFormat(pattern = DateUtil.PATTERN_DEFAULT)
    @TableField(fill = FieldFill.UPDATE)
    private Date updateTime;

    /** 更新人 */
    private String updateBy;

    /** 上架时间 */
    @JsonFormat(pattern = DateUtil.PATTERN_DEFAULT)
    private Date putawayTime;

    /** 版本 乐观锁 */
    private Integer version;
    
    /** 店铺名称 */
    @TableField(exist = false)
    private String shopName;
    
    /** sku列表 */
    @TableField(exist = false)
    private List<SkuProperties> skuPropertiesList;
    
    /** sku列表 */
    @TableField(exist = false)
    private List<ProdSku> skuList;

    /** 分组列表 */
    @TableField(exist = false)
    private List<String> tagList;
    
    public void convertProperties(boolean reverse) {
    	if(reverse) {
			this.skuPropertiesList = ProductUtil.prodProperties2List(skuProperties);
    		return;
    	}
    	
    	skuProperties = ProductUtil.list2ProdProperties(skuPropertiesList);
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    } 

    public void setProdName(String prodName) {
        this.prodName = prodName;
    }

    public String getProdName() {
        return prodName;
    }    
    
    public void setShopId(String shopId) {
        this.shopId = shopId;
    }

    public String getShopId() {
        return shopId;
    }    
    
    public void setOriPrice(BigDecimal oriPrice) {
        this.oriPrice = oriPrice;
    }

    public BigDecimal getOriPrice() {
        return oriPrice;
    }    
    
    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getPrice() {
        return price;
    }    
    
    public void setBrief(String brief) {
        this.brief = brief;
    }

    public String getBrief() {
        return brief;
    }    
    
    public void setContent(String content) {
        this.content = content;
    }

    public String getContent() {
        return content;
    }    
    
    public void setPic(String pic) {
        this.pic = pic;
    }

    public String getPic() {
        return pic;
    }    
    
    public void setImgs(String imgs) {
        this.imgs = imgs;
    }

    public String getImgs() {
        return imgs;
    }    
    
    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getStatus() {
        return status;
    }    
    
    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }

    public String getCategoryId() {
        return categoryId;
    }    
    
    public void setSoldNum(Integer soldNum) {
        this.soldNum = soldNum;
    }

    public Integer getSoldNum() {
        return soldNum;
    }    
    
    public void setTotalStocks(Integer totalStocks) {
        this.totalStocks = totalStocks;
    }

    public Integer getTotalStocks() {
        return totalStocks;
    }    
    
    public void setDeliveryMode(String deliveryMode) {
        this.deliveryMode = deliveryMode;
    }

    public String getDeliveryMode() {
        return deliveryMode;
    }    
    
    public void setDeliveryTemplateId(String deliveryTemplateId) {
        this.deliveryTemplateId = deliveryTemplateId;
    }

    public String getDeliveryTemplateId() {
        return deliveryTemplateId;
    }    
    
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getCreateTime() {
        return createTime;
    }    
    
    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public String getCreateBy() {
        return createBy;
    }    
    
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }    
    
    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public String getUpdateBy() {
        return updateBy;
    }    
    
    public void setPutawayTime(Date putawayTime) {
        this.putawayTime = putawayTime;
    }

    public Date getPutawayTime() {
        return putawayTime;
    }    
    
    public void setVersion(Integer version) {
        this.version = version;
    }

    public Integer getVersion() {
        return version;
    }

	public List<ProdSku> getSkuList() {
		return skuList;
	}

	public void setSkuList(List<ProdSku> skuList) {
		this.skuList = skuList;
	}

	public String getShopName() {
		return shopName;
	}

	public void setShopName(String shopName) {
		this.shopName = shopName;
	}

	public List<String> getTagList() {
		return tagList;
	}

	public void setTagList(List<String> tagList) {
		this.tagList = tagList;
	}

	public String getSkuProperties() {
		return skuProperties;
	}

	public void setSkuProperties(String skuProperties) {
		this.skuProperties = skuProperties;
	}

	public List<SkuProperties> getSkuPropertiesList() {
		return skuPropertiesList;
	}

	public void setSkuPropertiesList(List<SkuProperties> skuPropertiesList) {
		this.skuPropertiesList = skuPropertiesList;
	}
	
}
